﻿//var availableTags=["宋体","宋体","Batang","Times New Roman","MS PMincho","微软雅黑"];
$(document)
		.ready(

				function() {
					$("#uploaddiypicture").dialog({
						autoOpen:false
					});
					initBody();
					$("#chanping").draggable({
						drag:function(){
							$("#leftlist").css("left",document.getElementById("chanping").style.left);
							$("#leftlist").css("top",document.getElementById("chanping").style.top);
						}
					});
					$("#gongjukuang").draggable({
						drag:function(){
							$("#custom_choose").css("left",document.getElementById("gongjukuang").style.left);
							$("#custom_choose").css("top",document.getElementById("gongjukuang").style.top);
						}
					});

					$("#plbutton").click(function() {
						$("#productlist").slideToggle();
					});
					var v = document.getElementById("hiddenpicdetaillistsize");
					for ( var i = 0; i < v.value; i++) {
						document.getElementById("imgg" + i).style.width = document
								.getElementById("divv" + i).style.width;
						document.getElementById("imgg" + i).style.height = document
								.getElementById("divv" + i).style.height;
						$("#divv" + i).draggable({
							containment : '#bg'
						});
						$("#imgg" + i).resizable();
						$("#imgc" + i)
								.click(
										function() {
											var cancelnum = $(this).attr(
													"value");
											document.getElementById("flag"
													+ cancelnum).value = 0;
											document.getElementById("divv"
													+ cancelnum).style.display = "none";
										});

						$("#divv" + i).mouseover(
								function() {
									$(this).children().eq(0).children().eq(0)
											.fadeIn("slow");
								});
						$("#divv" + i).mouseout(
								function() {
									$(this).children().eq(0).children().eq(0)
											.fadeOut("slow");
								});

					}

					$("#inputdesignmsg").dialog({
						autoOpen : false,
						module : true,
						closeOnEscape : true,
						hide : "fadeout",
						modal : true,
						title : "设计信息填写",
						overlay : {
							opacity : 0.5,
							background : "black",
							overflow : 'auto'
						},
						position:[(window.innerWidth-400)/2,(window.innerHeight-300)/2],
						resizable:false
					});

					/*
					 * $("#inputdesignmsg1").dialog({ autoOpen : false, module :
					 * true, closeOnEscape : true, hide : "fadeout", modal :
					 * true, title : "设计信息填写", overlay : { opacity : 0.5,
					 * background : "black", overflow : 'auto' } });
					 */
					// 初始化字体family select
					$.getJSON("getLocalFont.action", function(data) {

						var fontfamilyselect = document
								.getElementById("fontfamilyselect");
						// availableTags="[";
						$.each(data.evnfont, function(index, value) {
							var o = document.createElement("option");
							o.innerHTML = value;
							fontfamilyselect.appendChild(o);
							// availableTags+=(value+",");
						});
						fontfamilyselect.value = "宋体";
						// availableTags=availableTags.substr(0,
						// availableTags.length-1);
						// availableTags+="]";

					});
					// 初始化字体大小select
					var sizeselect = document.getElementById("sizeselect");
					for ( var i = 10; i <= 200; i = i + 5) {
						var o = document.createElement("option");
						o.innerHTML = i;
						sizeselect.appendChild(o);
					}
					// 限制字体大小的输入
					$("#fontsize")
							.keyup(
									function() {
										var fontsizevalue = $("#fontsize")
												.val();
										if (fontsizevalue != '') {
											if (fontsizevalue > 200) {
												//alert("字体大小不能超过200！");
												$.weeboxs.open('字体大小不能超过200!', {
													title:'提示',
													timeout:5,
													showCancel:false,
													okBtnName: '确定',
												});
												$.weeboxs.open('字体大小不能超过200!', {
													title:'提示',
													timeout:5,
													showCancel:false,
													okBtnName: '确定',
												});
												$("#fontsize")
														.val(
																fontsizevalue
																		.substr(
																				0,
																				fontsizevalue.length - 1));
											} else if (!(/^[0-9]{1,3}$/
													.test(fontsizevalue))) {
												//alert("请输入数字！");
												$.weeboxs.open('请输入数字!', {
													title:'提示',
													timeout:5,
													showCancel:false,
													okBtnName: '确定',
												});
												$("#fontsize")
														.val(
																fontsizevalue
																		.substr(
																				0,
																				fontsizevalue.length - 1));
											}
										}
									});});
/*
 * function addAutocomplete(){ $( "#fontfamily" ).autocomplete({ source:
 * availableTags }); }
 */
function zhan1(can) {
	var ss = document.getElementById("second" + can);
	var uu = document.getElementById("uu" + can);
	var tu = document.getElementById("tupian" + can);/* 一级展开图片的ID */
	if (ss.style.display == "none" && ss.getAttribute("isclick") == "false") {
		$.post("dier.action", {
			id : can
		}, function(data) {
			var len = data.jsonob.length;
			ss.style.display = "block";
			tu.src = "img/nolines_minus.gif";
			for ( var i = 0; i < len; i++) {
				var li = document.createElement("li");
				li.innerHTML = "<a href='javascript:void(0);' style='font-size:11px;font-family:微软雅黑;'>"+ data.jsonob[i].seriesName + "</a>";
				li.setAttribute("onclick", "SendCar('"+ data.jsonob[i].seriesName + "')");
				uu.appendChild(li);
			}
			ss.setAttribute("isclick", "true");
		}, "json");
	} else if (ss.style.display == "none"&& ss.getAttribute("isclick") == "true") {
		ss.style.display = "block";
		tu.src = "img/nolines_minus.gif";
	} else {
		tu.src = "img/nolines_plus.gif";
		ss.style.display = "none";
	}
}

/*function SendCar(carname) {
	$.post("SendCarMark.action", {
		CarName : carname
	}, function(data) {
		var carpic = document.getElementById("Carpic");
		carpic.innerHTML = "";
		var l1;
		for ( var i = 0; i < data.jsonob1.length; i++) {
			l1 = document.createElement("div");
			l1.setAttribute("style","margin:5px;");
			var $img=$("<img class='diypic' onclick=addimg('" + data.jsonob1[i]+ "') src='" + data.jsonob1[i] + "' />");
			l1.innerHTML = $img;
			$img.draggable({
				revert : 'invalid',
				opacity : 0.7,
				helper : 'clone',
				scope : 'drop'
			});
			carpic.appendChild(l1);
		}
	}, "json");
}*/

function SendCar(carname) {
	$.post("SendCarMark.action", {
		CarName : carname
	}, function(data) {
		$("#Carpic").html("");
		for ( var i = 0; i < data.jsonob1.length; i++) {
			$("<img class='diypic' onclick=addimg('" + data.jsonob1[i]+ "') src='" + data.jsonob1[i] + "' />")
			.appendTo($("<div style='margin:5px;'></div>").appendTo($("#Carpic")))
			.draggable({
				revert : 'invalid',
				opacity : 0.7,
				helper : 'clone',
				scope : 'drop'
			});
		}
	}, "json");
}


var index = 0;
var arrayImg = new Array();
function addimg(url) {
	var div = document.getElementById("img"+index);
	div.setAttribute("style", "position:absolute;left:120px; top:200");
	arrayImg.push("img" + index);

	var img = document.createElement("img");
	img.setAttribute("style", "cursor:move");
	img.setAttribute("id", "pic" + index);
	img.setAttribute("src", url);

	var cancel = document.createElement("img");
	cancel.setAttribute("src", "img/cancel_03.png");
	cancel.setAttribute("style","display:block; position:relative; float:left; left:0; top:0; width:12px; height: 10px");
	cancel.setAttribute("onclick", "cancelimg(" + index + ")");

	var div2 = document.createElement("div");
	div2.setAttribute("style", "width:12px; height: 10px");
	div2.appendChild(cancel);
	div.appendChild(div2);
	div.appendChild(img);
	document.getElementById("bg").appendChild(div);
	$("#img" + index).mouseover(function() {
		$(this).children().eq(0).children().eq(0).fadeIn("slow");
	});
	$("#img" + index).mouseout(function() {
		$(this).children().eq(0).children().eq(0).fadeOut("slow");
	});
	$("#img" + index).draggable({
		containment : '#bg'
	});

	//判断图片是否超出
	var imgindex=$("#pic"+index);
	if(imgindex.width()>520){
		imgindex.parent().css("left","100px");
		imgindex.css("width","114px");
		imgindex.css("height","auto");
	}
	//------------------


	$("#pic" + index).resizable();
	$("#pic"+index).css("width","auto");
	$("#pic"+index).parent().css("width","auto");
	index++;
	$.getJSON("getTypesNameByTypeUrl.action", {
		url : url
	}, function(data) {
		var dd = data.typename;
		if (dd != "" && dd != 'null' && dd != null) {
			var temp = $("#forname").val();
			if (temp == "") {
				temp += dd;
			} else {
				temp += ("." + dd);
			}
			$("#forname").val(temp);
			//alert('添加图片的名字：' + temp);
			$.weeboxs.open('添加图片的名字'+temp, {
				title:'提示',
				timeout:5,
				showCancel:false,
				okBtnName: '确定',
			});
		}
	});
	showOthers(url);
}

function addwordimg(url, width, height) {
	var div = document.getElementById("img"+index);
	// div.setAttribute("style", "position:absolute;left:120;top:200;width:"+
	// width + ";height:" + height);
	div.setAttribute("style", "position:absolute;left:120;top:200;");
	arrayImg.push("img" + index);

	var img = document.createElement("img");
	// img.setAttribute("style", "cursor:move;width:" + width + ";height:" +
	// height);
	img.setAttribute("style", "cursor:move;");
	img.setAttribute("id", "pic" + index);
	img.setAttribute("src", url);
	var cancel = document.createElement("img");
	cancel.setAttribute("src", "img/cancel_03.png");
	cancel.setAttribute("style","display: none;position: relative;left: -10px;float: left;width: 12px;height: 10px;");
	cancel.setAttribute("onclick", "cancelimg(" + index + ")");
	var div2 = document.createElement("div");
	div2.setAttribute("style", "width:12px; height: 10px");
	div2.appendChild(cancel);
	div.appendChild(div2);
	div.appendChild(img);
	document.getElementById("bg").appendChild(div);
	$("#pic" + index).css("width", width);
	$("#pic" + index).css("height", height);
	document.getElementById("img" + index).style.width = document.getElementById("pic" + index).style.width;
	document.getElementById("img" + index).style.height = document.getElementById("pic" + index).style.height;
	$("#img" + index).mouseover(function() {
		$(this).children().eq(0).children().eq(0).fadeIn("slow");
	});
	$("#img" + index).mouseout(function() {
		$(this).children().eq(0).children().eq(0).fadeOut("slow");
	});
	$("#img" + index).draggable({
		containment : '#bg'
	});
	$("#pic" + index).resizable({
		stop : function() {
			$(this).parent().eq(0).css("width", $(this).width());
			$(this).parent().eq(0).css("height", $(this).height());
		}
	});
	index++;
}

function adddraw(url) {
	var div = document.createElement("div");
	div.setAttribute("id", "img" + index);
	div.setAttribute("style", "position:absolute;left:120; top:200");
	arrayImg.push("img" + index);

	var img = document.createElement("img");
	img.setAttribute("style", "cursor:move");
	img.setAttribute("id", "pic" + index);
	img.setAttribute("src", url);

	var cancel = document.createElement("img");
	cancel.setAttribute("src", "img/cancel_03.png");
	cancel
			.setAttribute(
					"style",
					"display:block; position:relative; float:left; left:0; top:0; width:12px; height: 10px");
	cancel.setAttribute("onclick", "cancelimg(" + index + ")");

	var div2 = document.createElement("div");
	div2.setAttribute("style", "width:12px; height: 10px");
	div2.appendChild(cancel);
	div.appendChild(div2);
	div.appendChild(img);
	document.getElementById("bg").appendChild(div);
	document.getElementById("pic" + index).style.width = 250;
	document.getElementById("pic" + index).style.height = 150;
	document.getElementById("img" + index).style.width = 250;
	document.getElementById("img" + index).style.height = 150;
	$("#img" + index).mouseover(function() {
		$(this).children().eq(0).children().eq(0).fadeIn("slow");
	});
	$("#img" + index).mouseout(function() {
		$(this).children().eq(0).children().eq(0).fadeOut("slow");
	});
	$("#img" + index).draggable({
		containment : '#bg'
	});
	$("#pic" + index).resizable({
		stop : function() {
			$(this).parent().eq(0).css("width", $(this).width());
			$(this).parent().eq(0).css("height", $(this).height());
		}
	});
	index++;
	$.getJSON("getTypesNameByTypeUrl.action", {
		url : url
	}, function(data) {
		var dd = data.typename;
		if (dd != "" && dd != 'null' && dd != null) {
			var temp = $("#forname").val();
			if (temp == "") {
				temp += dd;
			} else {
				temp += ("." + dd);
			}
			$("#forname").val(temp);
			//alert('添加图片的名字：' + temp);
			$.weeboxs.open('添加图片的名字'+temp, {
				title:'提示',
				timeout:5,
				showCancel:false,
				okBtnName: '确定',
			});
		}
	});
}

function cancelimg(index) {
	for ( var i = 0; i < arrayImg.length; i++) {
		if (arrayImg[i] == "img" + index) {
			arrayImg.splice(i, 1);
		}
	}
	document.getElementById("bg").removeChild(document.getElementById("img" + index));
}

function clearall() {
	for ( var i = 0; i < arrayImg.length; i++) {
		document.getElementById("bg").removeChild(
				document.getElementById(arrayImg[i]));
	}
}

var OriginImage = new Image();
function GetImageWidth(oImage) {
	if (OriginImage.src != oImage.src)
		OriginImage.src = oImage.src;
	return OriginImage.width;
}

function GetImageHeight(oImage) {
	if (OriginImage.src != oImage.src)
		OriginImage.src = oImage.src;
	return OriginImage.height;
}

var current = null;
function initcolor(evt) {
	var ColorHex = new Array('00', '33', '66', '99', 'CC', 'FF');
	var SpColorHex = new Array('FF0000', '00FF00', '0000FF', 'FFFF00',
			'00FFFF', 'FF00FF');
	var colorTable = '';// 调色板
	for ( var i = 0; i < 2; i++) {
		for ( var j = 0; j < 6; j++) {
			colorTable = colorTable + '<tr height=15>';
			colorTable = colorTable
					+ '<td width=15 style="background-color:#000000">';
			if (i == 0) {
				colorTable = colorTable
						+ '<td width=15 style="cursor:pointer;background-color:#'
						+ ColorHex[j] + ColorHex[j] + ColorHex[j]
						+ '" onclick="doclick(this.style.backgroundColor)">';
			} else {
				colorTable = colorTable
						+ '<td width=15 style="cursor:pointer;background-color:#'
						+ SpColorHex[j]
						+ '" onclick="doclick(this.style.backgroundColor)">';
			}
			colorTable = colorTable
					+ '<td width=15 style="background-color:#000000">';
			for (k = 0; k < 3; k++) {
				for (l = 0; l < 6; l++) {
					colorTable = colorTable
							+ '<td width=15 style="cursor:pointer;background-color:#'
							+ ColorHex[k + i * 3]
							+ ColorHex[l]
							+ ColorHex[j]
							+ '" onclick="doclick(this.style.backgroundColor)">';
				}
			}
		}
	}
	colorTable = '<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: '
			+ 'collapse" bordercolor="000000" width="300px" style="cursor:pointer;">'
			+ colorTable + '</table>';
	document.getElementById("colorpane").innerHTML = colorTable;
	var current_x = document.getElementById("custom_color").offsetLeft - 280;
	var current_y = document.getElementById("custom_color").offsetTop;
	// alert(current_x + "-" + current_y)
	document.getElementById("colorpane").style.left = current_x + "px";
	document.getElementById("colorpane").style.top = current_y + "px";
}

function doclick(obj) {
	document.getElementById("custom_color").style.background = obj;
	document.getElementsByName("color")[0].value = obj;
	document.getElementById("colorpane").style.display = "none";
	$("#custom_color table").hide();
}

function coloropen() {
	document.getElementById("colorpane").style.display = "";
}

function addword() {
	$.ajax({
		url : "word2pic.action",
		data : $('#addword').serialize(),
		type : "post",
		success : function(data) {
			addwordimg(data.filename, data.width, data.height);
		}
	});

}
var yulanPic;
function yulan() {/* 预览 */
	if ($("#hiddenBgPic").val() == 1) {
//		alert("请选择产品！");
		$.weeboxs.open('请选择产品!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	} else {
		var bodyWidth = document.body.clientWidth;
		var bodyHeight = document.body.clientHeight;

		var loading = document.getElementById("loading_img");
		loading.style.display = "block";
		loading.style.top = bodyHeight / 2 - 16 + "px";
		loading.style.left = bodyWidth / 2 - 16 + "px";

		var bgimg = document.getElementById("bg").style.backgroundImage.replace(/url\((.*?)\)/ig, "$1");
		var imgObj = "";
		for ( var i = 0; i < arrayImg.length; i++) {
//			var j = arrayImg[i].substring(3, arrayImg[i].length);
//			var imgurl = document.getElementById("pic" + j).src;
//			var width = parseInt(document.getElementById("pic" + j).style.width);
//			var height = parseInt(document.getElementById("pic" + j).style.height);
			var imgurl=$("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").attr("src");
			var width=parseInt($("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").width());
			var height = parseInt($("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").height());
			//新添加的图片的定位
			var top = parseInt(document.getElementById(arrayImg[i]).style.top)+10;
			var left = parseInt(document.getElementById(arrayImg[i]).style.left)-7;

			imgObj = imgObj + '{' + '"picurl":"' + imgurl + '","width":"'
					+ width + '","height":"' + height + '","top":"' + top
					+ '","left":"' + left + '"' + '}';
			if (i != arrayImg.length - 1)
				imgObj = imgObj + ',';
		}
		var reDesignSize = document.getElementById("hiddenpicdetaillistsize").value;
		if (reDesignSize != 0 && arrayImg.length != 0)
			imgObj = imgObj + ',';
		for ( var p = 0; p < reDesignSize; p++) {
			if (document.getElementById("flag" + p).value == 1) {
				var imgurl = document.getElementById("imgg" + p).src;
				var width = parseInt(document.getElementById("imgg" + p).style.width);
				var height = parseInt(document.getElementById("imgg" + p).style.height);
				//重定制图片的定位
				var top = parseInt(document.getElementById("divv" + p).style.top)+10;
				var left = parseInt(document.getElementById("divv" + p).style.left)-7;
				imgObj = imgObj + '{' + '"picurl":"' + imgurl + '","width":"'
						+ width + '","height":"' + height + '","top":"' + top
						+ '","left":"' + left + '"' + '}';
				if (p != reDesignSize - 1)
					imgObj = imgObj + ',';
			}
		}
		imgObj = "[" + imgObj + "]";
		var swidth = parseInt(document.body.scrollWidth);
		$.ajax({
			url : "preview.action",
			data : {
				bgPic : bgimg,
				swidth : swidth,
				pi : imgObj
			},
			type : "post",
			success : function(data) {// 显示预览层
				yulanPic = data.filename;
				$("#loading_img").fadeOut("slow");
				$("#fancybox-overlay").fadeIn("slow");
				$("#fancybox-img").attr("src", data.filename);
				$("#fancybox-wrap").fadeIn("slow");
			}
		});
	}
}

function viewclose() {
	$("#fancybox-overlay").fadeOut("slow");
	$("#fancybox-wrap").fadeOut("slow");
	$("._wPaint_menu").fadeOut("slow");
	$("#paintBody").fadeOut("slow");
}

function saveCustom() {
	var customname = document.getElementById("inputcustomname").value;
	var customcontent = document.getElementById("inputcustomcontent").value;
	var bgimg = document.getElementById("bg").style.backgroundImage.replace(/url\((.*?)\)/ig, "$1");
	var imgObj = "";
	for ( var i = 0; i < arrayImg.length; i++) {

		var imgurl=$("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").attr("src");
		var width=parseInt($("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").width());
		var height = parseInt($("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").height());

		var top = parseInt(document.getElementById(arrayImg[i]).style.top);
		var left = parseInt(document.getElementById(arrayImg[i]).style.left);
		imgObj = imgObj + '{' + '"picurl":"' + imgurl + '","width":"' + width
				+ '","height":"' + height + '","top":"' + top + '","left":"'
				+ left + '"' + '}';
		if (i != arrayImg.length - 1)
			imgObj = imgObj + ',';
	}
	var reDesignSize = document.getElementById("hiddenpicdetaillistsize").value;
	if (reDesignSize != 0 && arrayImg.length != 0)
		imgObj = imgObj + ',';
	for ( var p = 0; p < reDesignSize; p++) {
		if (document.getElementById("flag" + p).value == 1) {
			var imgurl = document.getElementById("imgg" + p).src;
			var width = parseInt(document.getElementById("imgg" + p).style.width);
			var height = parseInt(document.getElementById("imgg" + p).style.height);
			var top = parseInt(document.getElementById("divv" + p).style.top);
			var left = parseInt(document.getElementById("divv" + p).style.left);
			imgObj = imgObj + '{' + '"picurl":"' + imgurl + '","width":"'
					+ width + '","height":"' + height + '","top":"' + top
					+ '","left":"' + left + '"' + '}';
			if (p != reDesignSize - 1)
				imgObj = imgObj + ',';
		}
	}
	imgObj = "[" + imgObj + "]";
	var swidth = parseInt(document.body.scrollWidth);
	var ididid = $("#hiddencustomid").val();
	if (ididid == null || ididid == 0 || ididid == "") {
		$.ajax({
			url : "saveCustom.action",
			data : {
				bgPic : bgimg,
				swidth : swidth,
				pi : imgObj,
				filename : yulanPic,
				customName : customname,
				customcontent : customcontent
			},
			type : "post",
			success : function() {
//				alert("您的设计已经保存到购物车");
				$.weeboxs.open('您的设计已经保存到购物车!', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
				window.location.href = "showProducts.action";
			}
		});
	} else {

		$.ajax({
			url : "saveCustom.action",
			data : {
				customid : ididid,
				bgPic : bgimg,
				swidth : swidth,
				pi : imgObj,
				filename : yulanPic,
				customName : customname,
				customcontent : customcontent
			},
			type : "post",
			success : function() {
				//alert("您的设计已经保存到购物车");
				$.weeboxs.open('您的设计已经保存到购物车!', {
					title:'提示',
					timeout:5,
					showCancel:false,
					okBtnName: '确定',
				});
				window.location.href = "showCustom.action";
			}
		});
	}
}
function payForCustom() {
	$("#fancybox-overlay").fadeOut("slow");
	$("#fancybox-wrap1").fadeOut("slow");

	var bgimg = document.getElementById("bg").style.backgroundImage.replace(/url\((.*?)\)/ig, "$1");
	var imgObj = "";
	for ( var i = 0; i < arrayImg.length; i++) {
		var imgurl=$("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").attr("src");
		var width=parseInt($("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").width());
		var height = parseInt($("#"+arrayImg[i]).children().eq(1).children("img:eq(0)").height());

		var top = parseInt(document.getElementById(arrayImg[i]).style.top);
		var left = parseInt(document.getElementById(arrayImg[i]).style.left);
		imgObj = imgObj + '{' + '"picurl":"' + imgurl + '","width":"' + width
				+ '","height":"' + height + '","top":"' + top + '","left":"'
				+ left + '"' + '}';
		if (i != arrayImg.length - 1)
			imgObj = imgObj + ',';
	}
	var reDesignSize = document.getElementById("hiddenpicdetaillistsize").value;
	if (reDesignSize != 0)
		imgObj = imgObj + ',';
	for ( var p = 0; p < reDesignSize; p++) {
		if (document.getElementById("flag" + p).value == 1) {
			var imgurl = document.getElementById("imgg" + p).src;
			var width = parseInt(document.getElementById("imgg" + p).style.width);
			var height = parseInt(document.getElementById("imgg" + p).style.height);
			var top = parseInt(document.getElementById("divv" + p).style.top);
			var left = parseInt(document.getElementById("divv" + p).style.left);
			imgObj = imgObj + '{' + '"picurl":"' + imgurl + '","width":"'
					+ width + '","height":"' + height + '","top":"' + top
					+ '","left":"' + left + '"' + '}';
			if (p != reDesignSize - 1)
				imgObj = imgObj + ',';
		}
	}
	imgObj = "[" + imgObj + "]";
	var swidth = parseInt(document.body.scrollWidth);
	var varvar = document.getElementById("hiddencustomid").value;
	if (varvar == 0 || varvar == null || varvar == "") {
		window.location.href = "payForCustom.action?filename="+yulanPic+"&&bgPic=" + bgimg
				+ "&&swidth=" + swidth + "&&pi=" + imgObj;
	} else {
		window.location.href = "payForCustom.action?filename="+yulanPic+"&&bgPic=" + bgimg
				+ "&&swidth=" + swidth + "&&pi=" + imgObj + "&&customid=" + varvar;
	}
}

function changeBg(bgurl) {
	$("#hiddenBgPic").val(2);
	document.getElementById("bg").style.background = "url(" + bgurl
			+ ") no-repeat center bottom";
	document.cookie = "bg=" + bgurl;
}

function initBody() {
	// changeBg('${bgpiclist[0].picUrl}');
	initcolor();
}

function getCustomName() {
	$("#fancybox-wrap").fadeOut("slow");
	$("#fancybox-overlay").fadeOut("slow");
	$("#inputdesignmsg").dialog("open");
	//---------------非重设计的需要获取默认的产品名字------------------//
	var varvar = document.getElementById("hiddencustomid").value;
	if (varvar == 0 || varvar == null || varvar == "") {
		var bgimg = document.getElementById("bg").style.backgroundImage.replace(/url\((.*?)\)/ig, "$1");
		$.getJSON(
			"productUtil_getProductNameByBgpic.action",{
				pic:bgimg
			},function(data){
				$("#inputdesignmsg input:eq(0)").val(data.name);
			}
		);
	}
}

/*
 * function getPayForCustomName() { $("#inputdesignmsg1").dialog("open");
 * $("#fancybox-overlay").fadeOut("slow"); $("#fancybox-wrap").fadeOut("slow");
 * payForCustom(); }
 */

function inputCustomMsgButton() {
	if (document.getElementById("inputcustomname").value != null
			&& document.getElementById("inputcustomname").value != "") {
		$("#inputdesignmsg").dialog("close");
		saveCustom();
	} else {
		//alert("请填写设计名字！");
		$.weeboxs.open('请填写设计名字!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}
}

/*
 * function inputCustomMsgButton1() { if
 * (document.getElementById("inputcustomname1").value != null &&
 * document.getElementById("inputcustomname1").value != "") {
 * $("#inputdesignmsg1").dialog("close"); payForCustom(); } else {
 * alert("请填写设计名字！"); } }
 */

function changeSelectFamily(family) {
	$("#fontfamily").val(family);
}
function changeSelectSize(size) {
	$("#fontsize").val(size);
}
function saveImage() {
	var imageData = $("#wPaint").wPaint("image");
	imageData = imageData.substring(22);
	$.ajax({
		type : 'post',
		url : 'getImageByData.action',
		data : {
			imgStr : imageData
		},
		success : function(data) {
			adddraw(data.filename);
		},
		datatype : 'json'
	});
	viewclose();
}
function clearCanvas() {
	$("#wPaint").wPaint("clear");
}
function openPainter() {
	$("#wPaint").wPaint();
	$("._wPaint_menu").fadeIn("slow");
	$("#fancybox-overlay").fadeIn("slow");
	$("#paintBody").fadeIn("slow");
}
function min() {
	$("#custom_choose").slideToggle("slow");
}
function minProduct(){
	$("#leftlist").slideToggle("slow");
}

function checkaddword(){
	if($("#word").val()==''||$("#word").val()=='请输入自定义文字'){
//		alert("请输入文字");
		$.weeboxs.open('请输入文字!', {
			title:'提示',
			timeout:5,
			showCancel:false,
			okBtnName: '确定',
		});
	}else
	addword();
}


function addDrop(){
	$("[class='diypic']").draggable({
		revert : 'invalid',
		opacity : 0.7,
		helper : 'clone',
		scope : 'drop'
	});
	$("#bg").droppable({
		hoverClass : "hover",
      	scope : 'drop',
		drop : function(event, ui) {
			var ud = ui.draggable;
			if (ud.draggable("option", "helper") == "clone") {
				var div = document.getElementById("img"+index);
				div.setAttribute("style", "position:absolute;left:"+(ui.offset.left-385)+"px; top:"+(ui.offset.top-138)+"px");
				arrayImg.push("img" + index);
				document.getElementById("bg").appendChild(div);

				var cancel = document.createElement("img");
				cancel.setAttribute("src", "img/cancel_03.png");
				cancel.setAttribute("style","z-index:1000;display:block; position:relative; float:left; left:0; top:0; width:12px; height: 10px");
				cancel.setAttribute("onclick", "cancelimg(" + index + ")");
				var div2 = document.createElement("div");
				div2.setAttribute("style", "width:12px; height: 10px");
				div2.appendChild(cancel);
				div.appendChild(div2);

				ud.clone().appendTo($("#img"+index)).css({
					position : 'absolute',
				}).resizable();
				$("#img"+index).children().eq(1).children("img").attr("onclick","");
				$("#img"+index).children().eq(1).css("overflow","");
				$("#img"+index).children().eq(1).css("top","0px");
				$("#img"+index).children().eq(1).css("margin","0px");
				$("#img"+index).children().eq(1).css("left","-10px");
				$("#img" + index).mouseover(function() {
					$(this).children().eq(0).children().eq(0).fadeIn("slow");
				});
				$("#img" + index).mouseout(function() {
					$(this).children().eq(0).children().eq(0).fadeOut("slow");
				});
				$("#img" + index).draggable({
					containment : '#bg'
				});
				index++;
			}
		}
    });
}
